package com.ruoyi.bmxt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.entity.SysDept;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bmxt.domain.BmStudent;
import com.ruoyi.bmxt.service.IBmStudentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生管理Controller
 * 
 * @author 魏建波
 * @date 2023-02-24
 */
@RestController
@RequestMapping("/bmxt/student")
public class BmStudentController extends BaseController
{
    @Autowired
    private IBmStudentService bmStudentService;

    /**
     * 查询学生管理列表
     */
    @PreAuthorize("@ss.hasPermi('bmxt:student:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmStudent bmStudent)
    {
        startPage();
        List<BmStudent> list = bmStudentService.selectBmStudentList(bmStudent);
        return getDataTable(list);
    }

    /**
     * 导出学生管理列表
     */
    @PreAuthorize("@ss.hasPermi('bmxt:student:export')")
    @Log(title = "学生管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmStudent bmStudent)
    {
        List<BmStudent> list = bmStudentService.selectBmStudentList(bmStudent);
        ExcelUtil<BmStudent> util = new ExcelUtil<BmStudent>(BmStudent.class);
        util.exportExcel(response, list, "学生管理数据");
    }

    /**
     * 获取学生管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bmxt:student:query')")
    @GetMapping(value = "/{studentId}")
    public AjaxResult getInfo(@PathVariable("studentId") Long studentId)
    {
        return success(bmStudentService.selectBmStudentByStudentId(studentId));
    }

    /**
     * 新增学生管理
     */
    @PreAuthorize("@ss.hasPermi('bmxt:student:add')")
    @PostMapping
    public AjaxResult add(@RequestBody BmStudent bmStudent)
    {
        return toAjax(bmStudentService.insertBmStudent(bmStudent));
    }

    /**
     * 修改学生管理
     */
    @PreAuthorize("@ss.hasPermi('bmxt:student:edit')")
    @Log(title = "学生管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmStudent bmStudent)
    {
        return toAjax(bmStudentService.updateBmStudent(bmStudent));
    }

    /**
     * 删除学生管理
     */
    @PreAuthorize("@ss.hasPermi('bmxt:student:remove')")
    @Log(title = "学生管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studentIds}")
    public AjaxResult remove(@PathVariable Long[] studentIds)
    {
        return toAjax(bmStudentService.deleteBmStudentByStudentIds(studentIds));
    }

    @GetMapping("/treeselect")
    public AjaxResult treeselect(SysDept dept)
    {
        List<SysDept> depts = bmStudentService.selectDeptList(dept);
        List<TreeSelect> treeSelectList = bmStudentService.buildDeptStaffTreeSelect(depts);
        return AjaxResult.success(treeSelectList);
    }
}
